#include "random_helper.h"


#ifdef _WIN32
#include <windows.h>
#else
#include <dirent.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>


namespace zts {

	namespace rnd {

		int getRandomNum()
		{
			return rand();
		}

		bool boolWithProbability(float probability)
		{
			if (probability > 1.0f) probability = 1.0f;
			if (probability < 0.0f) probability = 0.0f;
			float value = ((float)getRandomNum()) / ((float)RAND_MAX);
			if (value <= probability) {
				return true;
			}

			return false;
		}

		double randBetween(double low, double high)
		{
			if (low > high) {
				double t = low; low = high; high = t;
			}
			double r = (double)getRandomNum() / ((double)RAND_MAX * 2);
			return low + (high - low)*r;
		}

		int randBetween(int low, int high)
		{
			if (low > high) {
				int t = low; low = high; high = t;
			}
			int r = getRandomNum() % (high - low + 1);
			return low + r;
		}

		//         float randBetweenWithAvg(float low, float high, float avg)
		//         {
		//             if (avg <= low || avg >= high) {
		//                 return avg;
		//             }
		//             float biasExp = (high-low) / (avg-low) - 1;
		//             float r = (float)getRandomNum()/((float)RAND_MAX*2);
		//             r = powf(r, biasExp);
		//             return low + (high-low)*r;
		//         }

	}
}

